package org.mifos.boss.persistence;

import java.math.BigInteger;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;



import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.mifos.boss.domainmodel.ApplicableAccountFeeType;
import org.mifos.boss.domainmodel.ClientCreationalData;
import org.mifos.boss.domainmodel.ClientCreationalData;
import org.mifos.boss.domainmodel.Customer;
import org.mifos.boss.domainmodel.Mobile2BossData;
import org.springframework.stereotype.Repository;


@Repository(value="customerPersistence")
public class CustomerPersistenceImpl extends BaseBossPersistence implements CustomerPersistenceInterface {
	
	 protected static Logger logger = Logger.getLogger(CustomerPersistenceImpl.class);

	public Customer createCustomer(Customer customer) {
		logger.debug("Saving new customer");
			
		save(customer);
		return customer;
	}

	public void saveClientExcahngeData(Mobile2BossData mobile2BossData) {
		logger.debug("Saving Customer Uploaded Data");
		save(mobile2BossData);
	}
	
	/*
	 *     public List<CustomerDto> getChildrenForParent(final Integer customerId, final String searchId, final Short officeId)
            throws PersistenceException {
        HashMap<String, Object> queryParameters = new HashMap<String, Object>();
        queryParameters.put("SEARCH_STRING", searchId + ".%");
        queryParameters.put("OFFICE_ID", officeId);
        List<CustomerDto> queryResult = executeNamedQuery(NamedQueryConstants.GET_ACTIVE_CHILDREN_FORPARENT,
                queryParameters);
        return queryResult;
    }
	 */
	
	public List<Mobile2BossData> getAllClientExchangeData(){
		
		logger.debug("get client data");
		
		// Retrieve session from Hibernate
		  Session session = sessionFactory.getCurrentSession();
		   
		  // Retrieve existing person
		  // Create a Hibernate query (HQL)
		  Query query = session.createQuery("FROM Mobile2BossData");
		   
		  return query.list();
		
		
	}
	
	//test method 
	private ClientCreationalData getDummyClientCreationalData(){
		
		ApplicableAccountFeeType aapFee = new ApplicableAccountFeeType();
		aapFee.setAmount("100");
		aapFee.setFeeID((new BigInteger("111")).intValue());
		
		List<ApplicableAccountFeeType> appFeeList = new ArrayList<ApplicableAccountFeeType>();
		
		appFeeList.add(aapFee);
		
		ClientCreationalData ccd = new ClientCreationalData();
		
		ccd.setClientName("hello");
		ccd.setClientStatus(Short.valueOf("1"));
//		ccd.setApplicableAccountType(appFeeList);
//		ccd.setApplicableAccountType(appFeeList);
		
		return ccd;
	}

}
